<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<title>Installing Qt toolkit version 4.2.3 on Linux</title>
<head>
<link rel="stylesheet" href="../format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Qt, Trolltech, installing qt, qt4.2.3, installation">
<meta name="description" content="This article describes installing of
 Qt toolkit version 4.2.3 on Linux.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

</head>

<body>

<div class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewVertical */
google_ad_slot = "4231459001";
google_ad_width = 120;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content">



<a href="/" title="Home">Home</a>


<h1>Installing Qt toolkit version 4.2.3 on Linux</h1>


<h2>Trolltech</h2>

<p>
<img src="../images/trolltech.gif" style="float:left">
Trolltech is a Norwegian software company. It was founded in 1994. Since then, 
the company has grown rapidly. Trolltech has got two product lines. The famous 
Qt toolkit and the Qtopia. Qtopia is an application framework for embedded linux 
devices. Today Trolltech has about 200 employees and more than 4400 customers in 60 countries.
Their headquaters is in Oslo. Trolltech is a new kind of a company. Together with MySQL AB, 
they are the most renowned companies that use the open source business model.
Trolltech's motto is <i>Create more, Code less</i>. 
</p>

<div class="center">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<h2>Qt toolkit</h2>

<p>
Qt is a cross-platform application development framework. The most famous 
applications using Qt are KDE, Opera, Google Earth and Skype. Qt was first 
publicly released on May 1995.  It is dual licenced. That means, it can be used 
for creating open source applications as well as proprietary
ones. Qt toolkit is a very powerful toolkit. Only the Java <b>Swing</b> toolkit can 
match it's capabilities. The great advantage of the Qt is that it is a way faster 
than Swing. The look and feel of the Qt is also superior to Swing.
On the other hand, the Swing toolkit is completely free of charge. For commercial 
development Qt is not free. Qt is well established in the open source community. 
Thousands of open source developes use Qt all over the world. 
</p>


<p>
In June 2005, Trolltech has released the latest major release. The long awaited 
4th version. The new version has a lot of 
new features, changes and improvements.
</p>

<p>
Trolltech introduced five new technologies.
</p>

<ul>
 <li>Tulip - a set of template container classes</i>
 <li>Interview - a model/view architecture for viewing items</li>
 <li>Arthur - the painting framework</li>
 <li>Scribe  - the Unicode text renderer</li>
 <li>Mainwindow - a modern action-based mainwindow, toolbar, menu, and docking architecture</li>

</ul>

<p>
The most exciting technology is definitely the Arthur painting framework.
</p>


<h2>Download</h2>

<p>
For non-commercial development Qt is free of charge. We can easily download 
the toolkit. We go to their <a href="http://trolltech.com/products/qt/downloads">download</a> 
page. As we are talking about linux installation here, we choose the Qt/X11 
Open Source Edition. The file name is qt-x11-opensource-src-4.2.3.tar.gz. The size of the file is 35.9MB. 
The file is archived and zipped. To unzip the file, we type the following command.
</p>


<pre>
tar -zxf qt-x11-opensource-src-4.2.3.tar.gz
</pre>


<p>
The command will unzip all the files to a directory qt-x11-opensource-src-4.2.3. 
The size of the directory is now 114.5 MB. Now it is time to carefully read the 
README and the INSTALL file. There we will find detailed installation instructions.
The installations is easy and straightforward. 
</p>

<h2>Install</h2>

<p>
We install the library the classic way. On Unix systems, installation of a 
software is divided into three steps.
</p>

<ul>
<li>Configuration</li>
<li>Building</li>
<li>Installation</li>
</ul>

<p>
First we run the configure script. The script will configure the library 
for our machine type. By default, the qt will be installed in 
/usr/local/Trolltech/Qt-4.2.3 directory. This can be changed by the -prefix 
parameter of the configure script. And it is the only option, that I used.  
I decided to install the library into the /usr/local/qt4 directory.
Note that the installation word has two meanings here. It is the whole process
 consisting of all three steps. And it also means 'moving files to specific directories', 
which is the last, third step.
</p>

<pre>
./configure -prefix /usr/local/qt4
</pre>


<pre class="explanation">
This is the Qt/X11 Open Source Edition.

You are licensed to use this software under the terms of either
the Q Public License (QPL) or the GNU General Public License (GPL).

Type 'Q' to view the Q Public License.
Type 'G' to view the GNU General Public License.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.

Do you accept the terms of either license? yes
</pre>

<p>
The script will ask for licence acceptance. After we type yes, the script continues. 
</p>

<pre class="explanation">
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/qt4

To reconfigure, run 'make confclean' and 'configure'.
</pre>

<p>
After a short period of time, the script will nicely inform about the outcome. 
</p>


<p>
The building of the qt toolkit takes several hours. It depends on the power 
of your processor. During the building my system went suddenly down. The temperature 
of the processor reached the critical value. This was due to my inefficient 
cooling probably. I always look at events optimistically. I figured out how 
to check temperature on the command line
</p>

<pre>
cat /proc/acpi/thermal_zone/THRM/temperature
</pre>

<p>
I also realized, that when you restart the building, it will continue 
where it has finished. 
</p>

<p>
After the process finished, I saw no message like 'building finished successfully'. 
This is common, but in my opinion not correct. 
</p>

<p>
The last step is installing, or moving files to the directories.
</p>

<pre>
sudo make install
</pre>

<p>
This command finishes the installation process. The library is now 
installed in /usr/local/qt4 directory. The size of the directory is 361.5 MB. 
As we can see, Qt is a huge library.
</p>

<p>
The last thing that we do, is adding the qt4 path to the PATH system variable. 
bash users, which are majority of linux users, need to edit the <i>.profile</i> file. 
</p>

<pre>
PATH=/usr/local/qt4/bin:$PATH
export PATH
</pre>

<p>
The changes will be active after another login.
</p>


<h2>Testing a small example</h2>


<p>
Finally we will write a small code example. 
</p>


<pre class="code">
#include &lt;QApplication&gt;
#include &lt;QWidget&gt;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget window;

    window.resize(250, 150);
    window.setWindowTitle("Simple example");
    window.show();

    return app.exec();
}
</pre>

<p>
To build this example, we will use a very handy tool called <i>qmake</i>.
</p>

<pre>
qmake -project
qmake
make
</pre>


<p>
If the qt4 installation directory is not a part of the PATH variable, we 
can provide the full path to the qmake tool.
</p>

<pre>
/usr/local/qt4/qmake -project
/usr/local/qt4/qmake
make
</pre>

<img src="../images/simpleqt4.jpg" alt="Simple Qt4 example">
<div class="figure">Simple Qt4 example</div>


<p>
Installation finished OK.
</p>

<div class="center">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br>

<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified April 4, 2008  <span class="copyright">&copy; 2007 - 2012 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->
</body>
</html>

